package com.fc.v2.controller;

import com.fc.v2.domain.AjaxResult;
import com.fc.v2.model.auto.SysRoleUser;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.service.auto.ISysRoleUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 用户角色关联controller
 * @Classname SysRoleUserController
 * @Date 2022/1/25 20:15
 * @Created by 87766867@qq.com
 */
@RestController
@RequestMapping("/SysRoleUserController")
public class SysRoleUserController {


    private final ISysRoleUserService iSysRoleUserService;

    public SysRoleUserController(ISysRoleUserService iSysRoleUserService) {
        this.iSysRoleUserService = iSysRoleUserService;
    }

    /***
     * 分页查询
     * @params [tablepar]
     * @returns com.github.pagehelper.PageInfo<com.fc.v2.model.auto.SysRoleUser>
     * @Date 2022/1/25 20:17
     * @Created by 87766867@qq.com
     */
    @GetMapping("/list")
    public PageInfo<SysRoleUser> list(Tablepar tablepar){
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<SysRoleUser> list= iSysRoleUserService.list();
        return new PageInfo<>(list);
    }



    /***
     * 根据id信息
     * @params [sysRoleUserId]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:17
     * @Created by 87766867@qq.com
     */
    @GetMapping("/getTenantId/{sysRoleUserId}")
    public AjaxResult getUserId(@PathVariable("sysRoleUserId") String sysRoleUserId){
        return AjaxResult.successData(iSysRoleUserService.getById(sysRoleUserId));
    }

    /****
     * 添加
     * @params [SysRoleUser]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysRoleUser SysRoleUser){
        return AjaxResult.successData(iSysRoleUserService.save(SysRoleUser));
    }
    /***
     * 修改
     * @params [SysRoleUser]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody SysRoleUser SysRoleUser){
        return AjaxResult.successData(iSysRoleUserService.updateById(SysRoleUser));
    }
    /***
     * 删除租户
     * @params [roleId]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @DeleteMapping("/delete/{id}")
    public  AjaxResult delete(@PathVariable("id") String id){
        return AjaxResult.successData(iSysRoleUserService.removeById(id));
    }


}
